/*
 * Filename DataReportDetermineMapping.java 2021年01月16日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 *
 * @author chenqiang
 */
package com.ehome.poct.core.service.mapping;

import com.ehome.poct.core.api.dto.check.TestReportDataConfigDTO;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctAnalysisDTO;
import com.ehome.poct.core.api.dto.check.gold.TestReportPoctDTO;
import com.ehome.poct.core.api.dto.check.gold.TestReportPoctUniDTO;
import com.ehome.poct.core.api.dto.report.ClinicalAnaluseResultDto;
import com.ehome.poct.core.api.dto.report.DataReportDetermine;
import com.ehome.poct.core.api.dto.report.ReportReqDTO;
import com.ehome.poct.core.api.dto.report.TestConfPoctUniAnalysisDTO;
import com.ehome.poct.core.api.vo.checkdata.TestDataDetailVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * 报告由哪些检测出类似生成配置
 *
 * @author chenqiang
 * @since 2021/01/16 09:57
 **/
@Mapper(componentModel = "spring")
public interface DataReportDetermineMapping {
    /**
     *DataReportDetermine 转化映射
     * @param dataConfigList 检测报告类型配置实体
     * @return 数据-对应的报告类型判定
     */
    List<DataReportDetermine> to(List<TestReportDataConfigDTO> dataConfigList);

    /**
     * DataReportDetermine 映射到 TestReportPoctDO
     * @param dataReportDetermine  数据-对应的报告类型判定
     * @param reportOrderReqVO 报告订单信息
     * @param testConfPoctAnalysisDO  单项检测
     * @return 单项检测报告实体
     */
    @Mappings({
            @Mapping(source = "dataReportDetermine.testData.testDataDetailId", target = "testPoctDataId"),
            @Mapping(source = "reportOrderReqVO.patientId",target = "patientId"),
            @Mapping(source = "dataReportDetermine.reportName",target = "name"),
            @Mapping(source = "testConfPoctAnalysisDO.confPoctAnalysisId",target = "analyseId"),
            @Mapping(source = "dataReportDetermine.reportCode",target="reportCode"),
            @Mapping(source = "dataReportDetermine.stripTypeCode",target ="stripTypeCode"),
            @Mapping(source = "dataReportDetermine.testPropertyType",target="reportType"),
            @Mapping(source = "dataReportDetermine.realStripTypeCode",target = "realStripTypeCode"),
            @Mapping(source = "orderNo",target="payOrderNo"),
            @Mapping(constant = "20",target="payStatus"),
            @Mapping(constant = "0",target="pushStatus"),
            @Mapping(source = "reportOrderReqVO.clinicId",target="clinicId"),
            @Mapping(expression = "java(makeDataAnalysisResult(dataReportDetermine.getTestPropertyType(),testConfPoctAnalysisDO.getResult(),dataReportDetermine.getTestData()))",target="dataAnalysisResult"),
            @Mapping(source = "clinicalAnaluseResult.clinicalAnalyseCode",target="clinicalAnalyseCode"),
            @Mapping(source = "clinicalAnaluseResult.clinicalAnalyseLevel",target ="clinicalAnalyseLevel")
    })
    TestReportPoctDTO to(DataReportDetermine dataReportDetermine, ReportReqDTO reportOrderReqVO,
                         TestConfPoctAnalysisDTO testConfPoctAnalysisDO, String orderNo,
                         ClinicalAnaluseResultDto clinicalAnaluseResult
    );

    /**
     * 生成联合报告的数据
     * @param reportName 报告名称
     * @param testDataA 检测数据1
     * @param testDataB 检测数据2
     * @param testConfPoctUniAnalysisDO 联合检测分析配置实体
     * @param reportOrderReqVO 报告订单请求参数
     * @return 联合检测数据
     */
    @Mappings({
            @Mapping(source = "testDataA.testDataDetailId",target="testPoctDataIdA"),
            @Mapping(source = "dataReportDetermine.testPropertyType",target="uniAnalyseType"),
            @Mapping(source = "reportOrderReqVO.patientId",target="patientId"),
            @Mapping(source = "testDataB.testDataDetailId",target="testPoctDataIdB"),
            @Mapping(source = "testDataA.stripTypeCode",target="stripTypeCodeA"),
            @Mapping(source = "testDataB.stripTypeCode",target="stripTypeCodeB"),
            @Mapping(source = "reportName",target="name"),
            @Mapping(source = "reportCode",target="reportCode"),
            @Mapping(target = "payOrderNo",source = "orderNo"),
            @Mapping(source = "testConfPoctUniAnalysisDO.testConfPoctUnionAnalysisId",target="uniAnalyseId"),
            @Mapping(expression = "java(makeDataAnalysisResult(dataReportDetermine.getTestPropertyType(),testConfPoctUniAnalysisDO.getStripTypeAResult(),testDataA))",target="analysisResultA"),
            @Mapping(expression = "java(makeDataAnalysisResult(dataReportDetermine2.getTestPropertyType(),testConfPoctUniAnalysisDO.getStripTypeBResult(),testDataB))",target="analysisResultB"),
            @Mapping(constant = "20",target="payStatus"),
            @Mapping(constant = "0",target="pushStatus"),
            @Mapping(source = "reportOrderReqVO.clinicId",target="clinicId"),
            @Mapping(target = "createTime", ignore = true),
            @Mapping(target = "createBy", ignore = true),
            @Mapping(target = "updateTime", ignore = true),
            @Mapping(target = "updateBy", ignore = true),
            @Mapping(target = "isDelete",ignore = true),
            @Mapping(source = "clinicalresult.clinicalAnalyseCode",target="clinicalAnalyseCode"),
            @Mapping(source = "clinicalresult.clinicalAnalyseLevel",target ="clinicalAnalyseLevel"),
            @Mapping(target = "realStripTypeCode",ignore = true)

    })
    TestReportPoctUniDTO to(String orderNo, String reportCode, String reportName, DataReportDetermine dataReportDetermine, DataReportDetermine dataReportDetermine2, TestDataDetailVO testDataA, TestDataDetailVO testDataB,
                            TestConfPoctUniAnalysisDTO testConfPoctUniAnalysisDO, ReportReqDTO reportOrderReqVO, ClinicalAnaluseResultDto clinicalresult);

    /**
     * 生成检测结果值
     *
     * @param testPropertyType     检测类型的属性
     * @param confAnalysisDoResult 检测配置分析结果
     * @param testData             检测数据
     * @return 报告的检测结果 （定性是 阴性，阳性，定量/半定量直接显示值)
     */
    default String makeDataAnalysisResult(Integer testPropertyType, String confAnalysisDoResult, TestDataDetailVO testData) {
        if(2==testPropertyType){
            return confAnalysisDoResult;
        }
        return testData.getValue1().toString();
    }
}
